package by.qizer.android.example.globalweather.util.json;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import by.qizer.android.example.globalweather.util.Util;

/**
 * @author Alexey Prybytkouski
 * 
 */
public class JSONParseCountries {

	private final JSONObject array;
	private List<String> countries;

	public JSONParseCountries(JSONObject array) {
		this.array = array;
		try {
			parse();
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	private void parse() throws JSONException {
		countries = new ArrayList<String>();
		JSONArray result = array.getJSONObject("search_api").getJSONArray(
				"result");

		for (int i = 0; i < result.length(); i++) {
			String city_name = result.getJSONObject(i).getJSONArray("areaName")
					.getJSONObject(0).getString("value");
			String countru_name = result.getJSONObject(i)
					.getJSONArray("country").getJSONObject(0)
					.getString("value");
			countries.add(city_name + ", " + countru_name);
			Util.ToLog(city_name + ", " + countru_name);
		}
	}

}
